#coding:utf-8
from requests_html import HTMLSession
import urllib
import urllib.request

# def getHtml(url):
#     page = urllib.request.urlopen(url)
#     html = page.read().decode()
#     return html

def get_url_html(url):
    session = HTMLSession()
    req = session.get(url)
#     print(req.html.text)
#     print(req.html.links)
#     print(req.html.absolute_links)

    sel = 'a'
    results = req.html.find(sel)
    for i in results:
        #打开图片的路径
        htmlUrl = i.attrs['href']
#         print(htmlUrl)
#         print(i)
        try:
            text1Url = i.attrs['title']
            print(text1Url+'---'+htmlUrl)
        except:
            print('无---'+htmlUrl)        

get_url_html('https://www.runoob.com/')
# print(getHtml('https://www.runoob.com/'))